Ext.define('appmod.view.resources.menu.Hierarchy', {
    extend: 'Ext.panel.Panel',
	alias: [
		'widget.menu-hierarchy-panel',
		'widget.menu.hierarchy.panel',
		'widget.menuhierarchypanel'
	], 
	
	requires: [
		'appmod.view.resources.menu.AllTreeGrid'
    ],	
   
	layout: {
        type: 'border'
    },
	constructor: function (config) {
		
		if (config.fieldStores) {
			this.store = config.store;
		}
        this.callParent(arguments);
    },


    initComponent: function() {
        var me = this;
		
		var store = me.store;
		
		// --- bunding node change ---
        Ext.applyIf(me, {
			changeRecordMap: Ext.create('Ext.util.HashMap'),
            dockedItems: [
                {
                    xtype: 'toolbar',
                    dock: 'top',
                    items: [
						{
                            xtype: 'button',
                            text: '保存更新',
							action:'save'
						},
                        {
                            xtype: 'button',
                            text: '加入菜单',
							action:'addnewmenu'
                        },
                        {
                            xtype: 'button',
                            text: '移除菜单',
							action:'removemenu'
                        },
                        {
                            xtype: 'button',
                            text: '刷 新',
							action:'reflesh'
                        }						
						
                    ]
                }
            ],
            items: [
                {
                    xtype: 'menu.alltree.grid',
					plugins: [
						Ext.create('Ext.grid.plugin.CellEditing', {
							clicktoEdit:2
		    			})
					],					
                    padding: '5 5 5 5',
                    //title: '菜单结构',
                    region: 'center',
					rootVisible:false,
					store:store,
                    viewConfig: {
            			plugins: {
                			ptype: 'treeviewdragdrop'
            			}
                    },
					listeners: {
						itemmove: {
							scope : me,
							fn : me.itemmove
						}					
					}
                }
            ]
        });

        me.callParent(arguments);
    },
	
	getChangedRecord:function() {
		return this.changeRecordMap;
	},
	
	
	// ---- mark the tree object record ---
	itemmove : function(tree, node, oldParent, newParent, index ) {
		// --- add all node change ,but save ---
		this.changeRecordMap.add(node.getId(), 'update');
	}

	
});